/**
 * This program is free software but WITHOUT ANY WARRANTY OR CONDITIONS OF ANY KIND.
 *
 * Copyright (C) 2008-2012 www.pretty-tools.com
 */

var WEBSLIDESHOW_UPDATE_CONFIGURATION_EVENT = "webslideshow-update-configuration";

/**
 * Configuration
 */
function wsshConfiguration()
{
    this.resourceBundle = yrprxFactory.createResourceBundle("chrome://webslideshow/locale/Configuration.properties");
    this.preferences = yrprxFactory.createPreferences("extensions.webslideshow.");
}

wsshConfiguration.prototype = {
    // Links
    get domainName() { return this.resourceBundle.getString("domain.name"); },
    get urlHomePage() { return this.resourceBundle.getString("home.page.url"); },
    get urlHelpSettingsPage() { return this.resourceBundle.getString("help.settings.page.url"); },
    get urlHelpRulesPage() { return this.resourceBundle.getString("help.rules.page.url"); },
    get urlPredefinedRules() { return this.resourceBundle.getString("predefined.rules.url"); },
    get urlSubscriptions() { return this.resourceBundle.getString("subscriptions.url"); },
    get urlInstalled() { return this.resourceBundle.getString("installed.url"); },
    // slide show delay
    get slideShowDelay() { return this.preferences.getInt("slideShowDelay", 3); },
    set slideShowDelay(slideShowDelay) { this.preferences.setInt("slideShowDelay", slideShowDelay); },
    // use single window for all slide shows
    get singleSlideShowDialog() { return this.preferences.getBool("singleSlideShowDialog", false); },
    set singleSlideShowDialog(singleSlideShowDialog) { this.preferences.setBool("singleSlideShowDialog", singleSlideShowDialog); },
    // slide auto-start
    get slideAutoStart() { return this.preferences.getBool("slideAutoStart", true); },
    set slideAutoStart(slideAutoStart) { this.preferences.setBool("slideAutoStart", slideAutoStart); },
    // show control panel only when mouse over it
    get showPanelOnlyWhenMouseOverIt() { return this.preferences.getBool("showPanelOnlyWhenMouseOverIt", false); },
    set showPanelOnlyWhenMouseOverIt(showPanelOnlyWhenMouseOverIt) { this.preferences.setBool("showPanelOnlyWhenMouseOverIt", showPanelOnlyWhenMouseOverIt); },
    // shrink images to fit screen
    get shrinkToFitScreen() { return this.preferences.getBool("shrinkToFitScreen", true); },
    set shrinkToFitScreen(shrinkToFitScreen) { this.preferences.setBool("shrinkToFitScreen", shrinkToFitScreen); },
    // zoom images to fit screen
    get zoomToFitScreen() { return this.preferences.getBool("zoomToFitScreen", false); },
    set zoomToFitScreen(zoomToFitScreen) { this.preferences.setBool("zoomToFitScreen", zoomToFitScreen); },
    // repeat
    get repeat() { return this.preferences.getBool("repeat", false); },
    set repeat(repeat) { this.preferences.setBool("repeat", repeat); },
    // scroll step
    get imageScrollStep() { return this.preferences.getInt("imageScrollStep", 50); },
    set imageScrollStep(imageScrollStep) { this.preferences.setInt("imageScrollStep", imageScrollStep); },
    // Zoom step
    get imageZoomStep() { return this.preferences.getInt("imageZoomStep", 20); },
    set imageZoomStep(imageZoomStep) { this.preferences.setInt("imageZoomStep", imageZoomStep); },
    // min image size
    get minImageWidth() { return this.preferences.getInt("minImageWidth", 300); },
    set minImageWidth(minImageWidth) { this.preferences.setInt("minImageWidth", minImageWidth); },
    get minImageHeight() { return this.preferences.getInt("minImageHeight", 300); },
    set minImageHeight(minImageHeight) { this.preferences.setInt("minImageHeight", minImageHeight); },
    // open image link to full screen
    get fullscreenImageLink() { return this.preferences.getBool("fullscreenImageLink", true); },
    set fullscreenImageLink(fullscreenImageLink) { this.preferences.setBool("fullscreenImageLink", fullscreenImageLink); },
    get fullscreenRuledImages() { return this.preferences.getBool("fullscreenRuledImages", true); },
    set fullscreenRuledImages(fullscreenRuledImages) { this.preferences.setBool("fullscreenRuledImages", fullscreenRuledImages); },
    // check for predefined rules
    get useSubscriptions() { return this.preferences.getBool("useSubscriptions", true); },
    set useSubscriptions(useSubscriptions) { this.preferences.setBool("useSubscriptions", useSubscriptions); },
    // check for predefined rules
    get updatePredefinedRules() { return this.preferences.getBool("updatePredefinedRules", true); },
    set updatePredefinedRules(updatePredefinedRules) { this.preferences.setBool("updatePredefinedRules", updatePredefinedRules); },
    // update interval in minutes
    get updateInterval() { return this.preferences.getInt("updateInterval", 1 * this.resourceBundle.getString("default.update.interval")); },
    set updateInterval(updateInterval) { this.preferences.setInt("updateInterval", updateInterval); },
    // last timestamp
    get updateTimeStamp() { return this.preferences.getString("updateTimeStamp", ""); },
    set updateTimeStamp(updateTimeStamp) { this.preferences.setString("updateTimeStamp", updateTimeStamp); },
    // Last-Modified time for predefined rules
    get predefinedRulesLastModified() { return this.preferences.getString("predefinedRulesLastModified", ""); },
    set predefinedRulesLastModified(predefinedRulesLastModified) { this.preferences.setString("predefinedRulesLastModified", predefinedRulesLastModified); },
    // time to wait before update in ms
    get waitBeforeUpdate() { return 1*this.resourceBundle.getString("wait.before.update"); },
    // is the first start
    get isFirstStart() { var firstStart = this.preferences.getBool("isFirstStart", true); if (firstStart) this.preferences.setBool("isFirstStart", false); return firstStart; }
}

wsshConfiguration.prototype.clone = function ()
{
    var cfg = {};

    for (var i in wsshConfig)
    {
        if (i == "resourceBundle" || i == "preferences")
            continue;

        cfg[i] = wsshConfig[i];
    }

    return cfg;
}

var wsshConfig = new wsshConfiguration();
